name: Host test

on: [push, pull_request]

jobs:
  host_test:
    name: Build and Test on Host
    runs-on: ubuntu-20.04
    container: espressif/idf:release-v4.3
    env:
      lwip: lwip-2.1.2
      lwip_contrib: contrib-2.1.0
      lwip_uri: http://download.savannah.nongnu.org/releases/lwip


    steps:
      - name: Checkout esp-protocols
        uses: actions/checkout@master
        with:
          path: esp-protocols

      - name: Build and Test
        shell: bash
        run: |
          apt-get update && apt-get install -y gcc-8 g++-8
          update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-8 800 --slave /usr/bin/g++ g++ /usr/bin/g++-8
          export LWIP_PATH=`pwd`/${{ env.lwip }}
          export LWIP_CONTRIB_PATH=`pwd`/${{ env.lwip_contrib }}
          wget --no-verbose ${lwip_uri}/${lwip}.zip
          unzip -oq ${lwip}.zip
          wget --no-verbose ${lwip_uri}/${lwip_contrib}.zip
          unzip -oq ${lwip_contrib}.zip
          . ${IDF_PATH}/export.sh
          cd $GITHUB_WORKSPACE/esp-protocols/components/esp_modem/examples/linux_modem
          idf.py build
          cd $GITHUB_WORKSPACE/esp-protocols/components/esp_modem/test/host_test
          idf.py build
          ./build/host_modem_test.elf -r junit -o junit.xml

      - name: Publish Results
        uses: EnricoMi/publish-unit-test-result-action@v1
        if: always()
        with:
          files: esp-protocols/components/esp_modem/test/host_test/junit.xml
